/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1665379443705_2475';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  config.middleware = [ 'errorHandler' ];

  config.security = {
    csrf: {
      enable: false,
    },
  };

  userConfig.mysql = {
    default: 'master',
    clients: {
      master: {
        host: '127.0.0.1',
        port: '3306',
        user: 'root',
        password: '123456',
        database: 'egg',
        connectionLimit: 10,
      },
      mysql2: {
        host: '127.0.0.1',
        port: '3306',
        user: 'root',
        password: '123456',
        database: 'egg',
        connectionLimit: 10,
      },
    },
  };

  config.sequelize = {
    dialect: 'mysql',
    database: 'egg',
    host: '127.0.0.1',
    port: 3306,
    username: 'root',
    password: '123456',
    // 配置数据库时间为东八区北京时间
    timezone: '+08:00',
    define: { // model的全局配置
      timestamps: true, // 添加create,update,delete时间戳
      paranoid: true, // 添加软删除
      freezeTableName: true, // 防止修改表名为复数
      underscored: true, // 防止驼峰式字段被默认转为下划线
    },
    // 打印日志
    logging: true,
    // 时间格式化
    dialectOptions: {
      dateStrings: true,
      typeCast: true,
    },
  };
  // config.swaggerdoc = {
  //   dirScanner: './app/controller',
  //   apiInfo: {
  //     title: 'egg-swagger-doc',
  //     description: 'swagger-ui for egg',
  //     version: '1.0.0',
  //   },
  //   schemes: [ 'http', 'https' ],
  //   consumes: [ 'application/json' ],
  //   produces: [ 'application/json' ],
  //   enableSecurity: false,
  //   // enableValidate: true, 没有实现这个功能
  //   routerMap: true, // 自动注册路由
  //   enable: true,
  // };

  return {
    ...config,
    ...userConfig,
  };
};
